<template>
  <div>
    editshippingaddress
    <van-row type="flex" align="center">
      <van-col span="2">
        <van-icon
          name="arrow-left"
          size="40"
          color="rgb(64, 150, 236)"
          @click="back"
        />
      </van-col>

      <van-col span="8" offset="6">编辑收货地址</van-col>
      <van-col span="4" offset="1" @click="edit">保存</van-col>
    </van-row>
    <hr style="margin-top:20px,color:rgba(137, 162, 162, 0.1)" />

    <van-address-edit
      v-model="addressInfo"
      :area-list="areaList"
      :address-info="addressInfo"
      :show-area="true"
      :show-detail="true"
      :show-set-default="true"
      show-delete
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-detail="onChangeDetail"
      @change-default="setDefAdress"
      
    />
  </div>
</template>

<script>
import { Toast } from "vant";

export default {
  data() {
    return {
      searchResult: [],
      addressInfo: {},
      areaList: {
        province_list: {
          110000: "北京省",
          120000: "天津市",
        },
        city_list: {
          110100: "北京市",
          120100: "天津市",
        },
        county_list: {
          110101: "东城区",
          110102: "西城区",
        },
      },
    };
  },
  methods: {
    setDefAdress(value){
      if(value===false) return
      //循环遍历数组，数组的每一项是否默认false
      //然后将当前的是否默认改为true
      // this.goods.forEach(item=>{
      //   item.isDeault=false
      //   if(item.id===this.$route.params.info.id) item.isDeault=trues
      // })



    },
    onSave(content) {
      // Toast('save');
      console.log(content);
    },
    onDelete() {
      Toast("delete");
    },
    edit() {},
    back() {},
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "成都",
            address: "w279",
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },
  created() {
    console.log(this.$route);
    this.addressInfo = this.$route.params.info;

    let reg = /.+?(省|市|自治区|自治州|县|区)/g;
  },
};
</script>

<style>
</style>